package com.duan.luren;

import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

public class ConnectionHelper {
    private static final String HOST = "192.168.16.113";
    private static final int HOST_PORT = 5672;

    private static final String USER_NAME = "admin";
    private static final String PASSWORD = "123";

    private static final String VIRTUAL_HOST = "/primeton";

    public static Connection getConnection() throws Exception {
        //定义一个连接工厂
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost(HOST);
        factory.setPort(HOST_PORT);
        factory.setVirtualHost(VIRTUAL_HOST);
        factory.setUsername(USER_NAME);
        factory.setPassword(PASSWORD);
//        factory.setAutomaticRecoveryEnabled(true);
        factory.setConnectionTimeout(30000);
        factory.setRequestedHeartbeat(60);
        return factory.newConnection();
    }
}
